﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data.SqlClient;
using System.Xml;
using System.Collections;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.User.Identity.IsAuthenticated)
            Response.Redirect("login.aspx");



  



    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Button1.Visible = false;
        Panel1.Visible = true ;
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        Panel1.Visible = false;
        Button1.Visible = true;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox1.Text = TextBox1.Text.Trim();
        if (TextBox1.Text.Length == 0)
        {
            Label1.Text = "请输入班级名称!";
            return;
        }
        //创建班级
        if (Panel1.Visible)
        {
            string strsql = "SELECT * FROM CLASS WHERE department='"+DropDownList1.Text+"' AND grade='" + DropDownList2.Text + "' AND class='" + TextBox1.Text+ "'";
            SqlDataReader sdr = SQLHelper.SQLHelper.ExecReader(strsql);
            if (sdr.Read())
            {
                Label1.Text = "该班级已存在!";
                return;
            }


            try
            {

                strsql = "insert into class (department,grade,class,created,owner) values ('" + DropDownList1.Text + "','" + DropDownList2.Text + "','" + TextBox1.Text + "','" + DateTime.Now + "','" + Page.User.Identity.Name + "')";
                SQLHelper.SQLHelper.ExecNonQuery(strsql);

            }
            catch (Exception ex)
            {
                Label1.Text = ex.Message;
                return;
            }
        }



        Response.AddHeader("Refresh", "0"); 


    }

}